Use case: CEC receive IT mode

This use case describes how to receive a CEC frame in Interrupt mode (IT mode) using HAL1 and HAL2.

Sequence diagram

@startuml

' Fix order of each column
participant "User application" as user
participant "<b>HAL CEC driver</b>"       as cec
participant "CEC IRQ handler" as isr

== CEC initialization / configuration / optional configuration / control ==

user -> cec : <color #Blue> HAL_CEC_Init</color>(hcec)
note right: <color #Blue>  Initializes the CEC mode according to the specified parameters in the handle.
cec --> user: HAL_OK
== CEC reception ==

isr -> cec : <font color=orange> HAL_CEC_IRQHandler()
note right: <font color=orange> interrupt when Rx event occurs
cec -> user : <font color=orange> HAL_CEC_RxCpltCallback() </font> user process for CEC Rx
...

note over user: <color #Blue> The user application has to: \n\
<color #Blue> copy the received data frame \n and can \n <color #Blue>swap the buffer pointer with HAL_CEC_ChangeRxBuffer( hcec, Rxbuffer )

group optional
user -> cec : <color #Blue> HAL_CEC_ChangeRxBuffer</color>( hcec, Rxbuffer )
note right: <color #Blue> set a new buffer pointer using HAL_CEC_ChangeRxBuffer()\n <color #Blue>within HAL_CEC_RxCpltCallback()
cec --> user: HAL_OK
end
...

== CEC reception error handling ==
group If hardware error occurs :

 alt Rx error detected
   box "Rx error handling" #LightYellow
    isr -> cec : <font color=orange> HAL_CEC_IRQHandler()
    note right: <font color=orange> interrupt when error
    cec -> user : <font color=orange> HAL_CEC_ErrorCallback() </font> user process CEC line error
   end box
 end

@enduml

Code snippet

HAL1

HAL2

CEC_HandleTypeDef                   hcec;
uint8_t                             Tab_Rx[3];
uint8_t                             New_RxBuffer[3];




hcec.Instance                       = CEC;


hcec.Init.OwnAddress                = CEC_OWN_ADDRESS_3;



hcec.Init.SignalFreeTime            = CEC_DEFAULT_SFT;
hcec.Init.Tolerance                 = CEC_STANDARD_TOLERANCE;
hcec.Init.BRERxStop                 = CEC_RX_STOP_ON_BRE;
hcec.Init.BREErrorBitGen            = CEC_BRE_ERRORBIT_GENERATION;
hcec.Init.LBPEErrorBitGen           = CEC_LBPE_ERRORBIT_GENERATION;
hcec.Init.BroadcastMsgNoErrorBitGen = CEC_BROADCASTERROR_ERRORBIT_GENERATION;
hcec.Init.SignalFreeTimeOption      = CEC_SFT_START_ON_TXSOM;
hcec.Init.ListenMode                = CEC_FULL_LISTENING_MODE;

hcec.Init.RxBuffer                  = Tab_Rx;
HAL_CEC_Init(hcec);

/* After Rx complete */
HAL_CEC_RxCpltCallback(&hcec)
{
  HAL_CEC_ChangeRxBuffer(&hcec, New_RxBuffer);
}
hal_cec_handle_t                    hcec;
uint8_t                             rx_data_frame[2];
uint8_t                             new_rx_data_frame[2];
hal_cec_header_t                    p_rx_header;

uint32_t                            max_size_byte = 0x02;
hal_cec_config_t                    config;

HAL_CEC_Init(&hcec, HAL_CEC);

config.own_address = HAL_CEC_OWN_ADDR_5;
HAL_CEC_SetConfig(&hcec, &config);


/* Optional configurations */
HAL_CEC_SetSignalFreeTimeDuration(&hcec, HAL_CEC_SIG_FREETIME_DURATION_AUTO);
HAL_CEC_SetRxTolerance(&hcec, HAL_CEC_RX_TOLERANCE_STANDARD);
HAL_CEC_EnableRxStopUponBitRisingErr(&hcec);
HAL_CEC_EnableBitRisingErrGen(&hcec);
HAL_CEC_EnableLongBitPeriodErrGen(&hcec);
HAL_CEC_EnableBroadcastErrGen(&hcec);
HAL_CEC_SetSignalFreeTimeStart(&hcec, HAL_CEC_SIG_FREETIME_ON_MSG_START);
HAL_CEC_SetListenMode(&hcec, HAL_CEC_LISTEN_MODE_RECEIVE_ALL_MSG);

HAL_CEC_Start_IT(&hcec, &p_rx_header, rx_data_frame, max_size_byte);

/* After Rx complete */
HAL_CEC_RxCpltCallback(&hcec)
{
  HAL_CEC_SetRxBuffer(&hcec, &p_rx_header, new_rx_data_frame, max_size_byte);
}

Key changes

  1. In HAL2, optional RX-related settings are configured through dedicated APIs (for example HAL_CEC_SetRxTolerance) rather than through handle init fields.

  2. In HAL2, reception is started with HAL_CEC_Start_IT and the RX buffer can be updated using HAL_CEC_SetRxBuffer.

  3. HAL2 uses typed configuration structures (for example hal_cec_config_t and hal_cec_header_t) and buffers passed as parameters.